package info.javafans.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTime {
	private int year;// 2011
	private int month;// 1
	private int day;// 24

	private int hour;// 18
	private int min;// 14
	private int sec;// 48

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public int getHour() {
		return hour;
	}

	public void setHour(int hour) {
		this.hour = hour;
	}

	public int getMin() {
		return min;
	}

	public void setMin(int min) {
		this.min = min;
	}

	public int getSec() {
		return sec;
	}

	public void setSec(int sec) {
		this.sec = sec;
	}

	/**
	 * 返回简单格式的日期时间字符串 格式：
	 * yyyy-MM-dd hh:mm:ss 如：2010-1-1日 不进行补0
	 * 
	 * @return
	 */
	public String getShortDateTime() {
		return "" + year + "-" + month + "-" + day + " " + hour + ":" + min
				+ ":" + sec;
	}

	/**
	 * 返回格式化的日期时间字符串 格式：
	 * yyyy-MM-dd hh:mm:ss 如：2010-01-01 补0
	 * 
	 * @return
	 */
	public String getFmtDateTime() {
		String sMonth = this.month < 10 ? "0" + this.month : "" + this.month;
		String sDay = this.day < 10 ? "0" + this.day : "" + this.day;
		String sHour = this.hour < 10 ? "0" + this.hour : "" + this.hour;
		String sMin = this.min < 10 ? "0" + this.min : "" + this.min;
		String sSec = this.sec < 10 ? "0" + this.sec : "" + this.sec;

		return "" + year + "-" + sMonth + "-" + sDay + " " + sHour + ":" + sMin
				+ ":" + sSec;
	}

	/**
	 * 返回中文格式字符串 格式：2011年1月1日 18时39分12秒
	 */
	public String getZhDateTime() {
		return "" + year + "年" + month + "月" + day + "日 " + hour + "时" + min
				+ "分" + sec+"秒";
	}
	
	/**
	 * 返回中文月份
	 * 如：十一月
	 * @return
	 */
	public String getZhMonth() {
		String zhMonth = "";
		
		switch(this.month) {
		case 1:
			zhMonth = "一";
			break;
		case 2:
			zhMonth = "二";
			break;
		case 3:
			zhMonth = "三";
			break;
		case 4:
			zhMonth = "四";
			break;
		case 5:
			zhMonth = "五";
			break;
		case 6:
			zhMonth = "六";
			break;
		case 7:
			zhMonth = "七";
			break;
		case 8:
			zhMonth = "八";
			break;
		case 9:
			zhMonth = "九";
			break;
		case 10:
			zhMonth = "十";
			break;
		case 11:
			zhMonth = "十一";
			break;
		case 12:
			zhMonth = "十二";
			break;
		}
		return zhMonth + "月";
	}
	
	/**
	 * 构造DateTime，由yyyy-MM-dd hh:mm:ss字符串构造
	 * @param datetime
	 * @return
	 */
	public static DateTime format(String date) {
		DateTime datetime = new DateTime();
		
		String year = date.substring(0, 4);
		String month = date.substring(5, 7);
		String day = date.substring(8, 10);
		String hour = date.substring(11, 13);
		String min = date.substring(14, 16);
		String sec = date.substring(17, 19);
		
		datetime.setYear(new Integer(year));
		datetime.setMonth(new Integer(month));
		datetime.setDay(new Integer(day));
		datetime.setHour(new Integer(hour));
		datetime.setMin(new Integer(min));
		datetime.setSec(new Integer(sec));
		
		return datetime;
	}
	
	/**
	 * 获得当前时间的String
	 * @return
	 */
	public static String getNowTimeStr(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String result = sdf.format(date);
		return result;
	}
	
	/**
	 * 获得当前时间的DateTimes
	 * @return
	 */
	public static DateTime getNowTime(){
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String result = sdf.format(date);
		
		return DateTime.format(result);
	}
}
